import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

ImageProvider getAssetImage(String url, {String format: 'png'}) {
  return AssetImage(getImgPath(url, format: format));
}

///  如果url是本地全路径或者为空则直接返回，否则进行全路径的拼接
///
///  [url] 本地路径名或者文件名
///  [format] 如果是非空文件名时根据该后缀进行拼接
String getImgPath(String url, {String format: 'png'}) {
  return url == null || url.isEmpty || url.contains("assets") ? url : 'assets/images/$url.$format';
}

ImageProvider getImageProvider(String imageUrl, {String holderImg: 'none'}) {
  if (imageUrl == null || imageUrl.isEmpty) {
    return AssetImage(getImgPath(holderImg));
  }
  return CachedNetworkImageProvider(imageUrl);
}


